home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_024 / conquest / conqpl.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  17KB  |  428 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3. #include "structs.h"
  4. #include "vars.h"
  5.  
  6. bl2st_planet()
  7. {
  8.         char tf_char, pl_char; 
  9.         int tf_num, planet_num;
  10.         tplanet *pplanet; 
  11.         int factors,starnum; 
  12.         boolean see, done;
  13.         char iline[81]; 
  14.         int ind,amount; 
  15.         char dum;
  16.         printf("last");
  17.         cle3r_left();
  18.         point(1,19);
  19.         printf("Firing TF:");
  20.         get_char(&tf_char);
  21.         tf_num = tf_char-'A'+1;
  22.         if ( (tf_num < 1) || (tf_num > 26) ) {
  23.                 error_message();
  24.                 printf(" !Illegal tf");
  25.         }
  26.         else if ( tf[player][tf_num].dest==0 ) {
  27.                 error_message();
  28.                 printf(" !Nonexistent tf");
  29.         }
  30.         else if ( tf[player][tf_num].eta!=0 ) {
  31.                 error_message();
  32.                 printf(" !Tf is not in normal space   ");
  33.         }
  34.         else if ( tf[player][tf_num].blasting ) {
  35.                 error_message();
  36.                 printf(" !Tf is already blasting     ");
  37.         }
  38.         else if ( (tf[player][tf_num].b == 0) && (tf[player][tf_num].c == 0) ) {
  39.                 error_message();
  40.                 printf(" !Tf has no warships         ");
  41.         }
  42.         else {
  43.                 starnum = tf[player][tf_num].dest;
  44.                 pplanet = stars[starnum].first_planet;
  45.                 if ( pplanet==nil ) {
  46.                         error_message();
  47.                         printf(" !No planets at star %c       ", 
  48.                                                         starnum + 'A' - 1);
  49.                 }
  50.                 else {
  51.                         point(1,20);
  52.                         printf("Target colony ");
  53.                         if ( pplanet->next== nil ) {
  54.                                 printf("%2d",pplanet->number);
  55.                         }
  56.                         else {
  57.                                 printf(":");
  58.                                 get_char(&pl_char);
  59.                                 planet_num = pl_char -'0';
  60.                                 done = false;
  61.                                 while ( ! done ) {
  62.                                         if ( (pplanet->number==planet_num)  )
  63.                                                 done = true;
  64.                                         else {
  65.                                                 if ( pplanet->next==nil )
  66.                                                         done = true;
  67.                                                 else
  68.                                                         pplanet = pplanet->next;
  69.                                         };
  70.                                 };
  71.                                 if ( pplanet->number != planet_num ) {
  72.                                      error_message();
  73.                                      printf(" !No such planet at this star ");
  74.                                      pplanet = nil;
  75.                                 };
  76.                         };
  77.                         if ( pplanet != nil ) {
  78.                                 if ( pplanet->team==ENEMY ) {
  79.                                         error_message();
  80.                                         printf(" !Conquer it first!");
  81.                                 }
  82.                                 else if ( (pplanet->team==player) 
  83.                                                 && (! pplanet->conquered)
  84.                                     ) {
  85.                                         error_message();
  86.                                         printf(" !That is a human colony!!    ");
  87.                                 }
  88.                                 else {
  89.                                    factors = weapons[player] 
  90.                                         * ((tf[player][tf_num].c * c_guns) +
  91.                                             (tf[player][tf_num].b * b_guns));
  92.                                         point(1,21);
  93.                                         printf("Units (max %3d) :", factors/4);
  94.                                         point(18,21);
  95.                                         get_line(iline,&ind,false);
  96.                                         get_token(iline,&ind,&amount,&dum);
  97.                                         if ( amount < 0 )
  98.                                            factors = 0;
  99.                                         else if ( amount > 0 )
  100.                                            factors = min (factors, amount * 4);
  101.                                         tf[player][tf_num].blasting = true;
  102.                                         point(1,22);
  103.                                         printf("Blasting %3d units", factors/4);
  104.                                         blast(pplanet,factors);
  105.                                         point(1,23);
  106.                                         left_line[23] = true;
  107.                                         putchar(pplanet->pstar+'A'-1);
  108.                                         pplanet->psee_capacity = pplanet->capacity;
  109.                                         see = true;
  110.         if ( ((y_cursor > 21) && (x_cursor >= 50)) ||
  111.             (y_cursor > 24) ) {
  112.                 pause();
  113.                 clear_field();
  114.                 point(50,1);
  115.         };
  116.         printf("%d:%2d                         ", pplanet->number, pplanet->psee_capacity);
  117.         point(x_cursor + 5, y_cursor);
  118.         x_cursor = x_cursor - 5;
  119.         if ( pplanet->psee_capacity==0 )
  120.                 printf(" Decimated");
  121.         else if ( (pplanet->team==none) && see )
  122.                 printf(" No colony");
  123.         else if ( pplanet->team==player ) {
  124.                 printf("(%2d,/%3d)", pplanet->inhabitants, pplanet->iu);
  125.                 if ( pplanet->conquered )
  126.                         printf("Con");
  127.                 else
  128.                         printf("   ");
  129.                 if ( pplanet->mb!=0 )
  130.                         printf("%2dmb", pplanet->mb);
  131.                 else
  132.                         printf("    ");
  133.                 if ( pplanet->amb!=0 )
  134.                         printf("%2damb", pplanet->amb);
  135.         } 
  136.         else if ( (pplanet->team==ENEMY) && see ) {
  137.                 printf("*EN*");
  138.                 if ( see && pplanet->conquered ) {
  139.                         printf("Conquered");
  140.                 } 
  141.                 else
  142.                         printf("   ");
  143.                 if ( pplanet->under_attack ) {
  144.                         if ( pplanet->mb != 0 )
  145.                                 printf("%2dmb", pplanet->mb);
  146.                         else
  147.                                 printf("    ");
  148.                         if ( pplanet->amb != 0 )
  149.                                 printf("%2damb", pplanet->amb);
  150.                 };
  151.         };
  152.         point(x_cursor,y_cursor + 1);
  153.  
  154.                                 };
  155.                         };
  156.                 };
  157.         };
  158. }
  159.  
  160. inputplayer()
  161. {
  162.         char key; 
  163.         boolean fin;
  164.         point(33,20);
  165.         printf("* Movement *    ");
  166.         fin=false;
  167.         do {
  168.                 point(1,18);
  169.                 printf("?                             ");
  170.                 point(2,18);
  171.                 get_char(&key);
  172.                 switch ( key ) {
  173.                 case 'M': 
  174.                         printmap();
  175.                         break;
  176.                 case 'B': 
  177.                         bl2st_planet();
  178.                         break;
  179.                 case 'G': 
  180.                 case ' ': 
  181.                         fin=true;
  182.                         break;
  183.                 case 'H': 
  184.                         help(1);
  185.                         break;
  186.                 case 'L': 
  187.                         land();
  188.                         break;
  189.                 case 'D': 
  190.                         send_tf();
  191.                         break;
  192.                 case 'S': 
  193.                         starsum();
  194.                         break;
  195.                 case 'N': 
  196.                         make_tf();
  197.                         break;
  198.                 case 'J': 
  199.                         join_tf();
  200.                         break;
  201.                 case 'C': 
  202.                         print_col();
  203.                         break;
  204.                 case 'R': 
  205.                         ressum();
  206.                         break;
  207.                 case 'Q':
  208.                         fin = true;
  209.                         quit();
  210.                         break;
  211.                 case '?':
  212.                         break;
  213.                 case 'T': 
  214.                         tfsum();
  215.                         break;
  216.                 default:
  217.                         error_message();
  218.                         printf("  !illegal command");
  219.                 };  /*switch (*/
  220.         } 
  221.         while (!fin);
  222. }
  223.  
  224.  
  225.  
  226. land()
  227. {
  228.         char tfc,trc,planc; 
  229.         boolean see;
  230.         int x,y,room_left,tfnum,transports,planet_num;
  231.         int starnum,ind; 
  232.         char iline[81]; 
  233.         boolean found;
  234.         struct stplanet  *pplanet;
  235.         printf("and tf:");
  236.         get_char(&tfc);
  237.         cle3r_left();
  238.         tfnum = tfc-'A'+1;
  239.         if ( (tfnum<1) || (tfnum>26) ) {
  240.                 error_message();
  241.                 printf("  !illegal tf");
  242.         }
  243.         else if ( (tf[player][tfnum].dest==0)) {
  244.                 error_message();
  245.                 printf("  !nonexistent tf");
  246.         }
  247.         else if ( (tf[player][tfnum].eta!=0) ) {
  248.                 error_message();
  249.                 printf("  !tf is not in normal space  ");
  250.         }
  251.         else {
  252.                 starnum= tf[player][tfnum].dest;
  253.                 pplanet= stars[starnum].first_planet;
  254.                 if ( pplanet==nil ) {
  255.                         error_message();
  256.                         printf("  !no planets at this star    ");
  257.                 }
  258.                 else if ( tf_stars[starnum][ENEMY]>0 ) {
  259.                         error_message();
  260.                         printf("  !enemy ships present");
  261.                 }
  262.                 else {
  263.                         point(11,18);
  264.                         printf(" planet ");
  265.                         if ( pplanet->next==nil ) {
  266.                                 planet_num = pplanet->number;
  267.                                 printf("%d", planet_num);
  268.                         } 
  269.                         else {
  270.                                 printf(":");
  271.                                 get_char(&planc);
  272.                                 planet_num = planc-'0';
  273.                                 found=false;
  274.                                 while ( (pplanet!= nil) && ! found){
  275.                                         if ( pplanet->number == planet_num )
  276.                                                 found=true;
  277.                                         else pplanet = pplanet->next;
  278.                                 };
  279.                                 if ( ! found ) {
  280.                                         planet_num = 0;
  281.                                         error_message();
  282.                                         printf(" !Not a habitable planet ");
  283.                                 }
  284.                         };
  285.                         if ( planet_num != 0 ) {
  286.                                 if ( (pplanet->team == ENEMY) || ((pplanet->team == player)
  287.                                     && (pplanet->conquered))  ) {
  288.                                         error_message();
  289.                                         printf("  !Enemy infested planet  !!  ");
  290.                                 }
  291.                                 else {    /*get the number of transports*/
  292.                                         room_left = pplanet->capacity - pplanet->inhabitants;
  293.                                         point(1,19);
  294.                                         printf(" transports:");
  295.                                         get_line(iline,&ind,false);
  296.                                         get_token(iline,&ind,&transports,&trc);
  297.                                         if ( transports==0 ) transports = tf[player][tfnum].t;
  298.                                         if ( transports < 1 ) {
  299.                                                 error_message();
  300.                                                 printf("  !illegal transports");
  301.                                         }
  302.                                         else if ( transports > tf[player][tfnum].t ) {
  303.                                                 error_message();
  304.                                                 printf("  !only %2d transports in tf", tf[player][tfnum].t);
  305.                                         }
  306.                                         else if ( transports > room_left ) {
  307.                                                 error_message();
  308.                                                 printf("  !only room for %2d transports", room_left);
  309.                                         }
  310.                                         else {
  311.                                                 pplanet->team = player;
  312.                                                 if ( pplanet->inhabitants==0 ) {
  313.                                                         col_stars[starnum][player]++;
  314.                                                 };
  315.                                                 pplanet->inhabitants=pplanet->inhabitants+transports;
  316.                                                 pplanet->iu=pplanet->iu + transports;
  317.                                                 tf[player][tfnum].t=tf[player][tfnum].t-transports;
  318.                                                 x=tf[player][tfnum].x; 
  319.                                                 y=tf[player][tfnum].y;
  320.                                                 if ( board[x][y].enemy == ' ' ) {
  321.                                                         board[x][y].enemy = '@';
  322.                                                         update_board(x,y,left);
  323.                                                 };
  324.                                                 point(1,20);
  325.                                                 putchar(starnum+'A'-1);
  326.                                                 see = true;
  327.         if ( ((y_cursor > 21) && (x_cursor >= 50)) ||
  328.             (y_cursor > 24) ) {
  329.                 pause();
  330.                 clear_field();
  331.                 point(50,1);
  332.         };
  333.         printf("%d:%2d                         ", pplanet->number, pplanet->psee_capacity);
  334.         point(x_cursor + 5, y_cursor);
  335.         x_cursor = x_cursor - 5;
  336.         if ( pplanet->psee_capacity==0 )
  337.                 printf(" Decimated");
  338.         else if ( (pplanet->team==none) && see )
  339.                 printf(" No colony");
  340.         else if ( pplanet->team==player ) {
  341.                 printf("(%2d,/%3d)", pplanet->inhabitants, pplanet->iu);
  342.                 if ( pplanet->conquered )
  343.                         printf("Con");
  344.                 else
  345.                         printf("   ");
  346.                 if ( pplanet->mb!=0 )
  347.                         printf("%2dmb", pplanet->mb);
  348.                 else
  349.                         printf("    ");
  350.                 if ( pplanet->amb!=0 )
  351.                         printf("%2damb", pplanet->amb);
  352.         } 
  353.         else if ( (pplanet->team==ENEMY) && see ) {
  354.                 printf("*EN*");
  355.                 if ( see && pplanet->conquered ) {
  356.                         printf("Conquered");
  357.                 } 
  358.                 else
  359.                         printf("   ");
  360.                 if ( pplanet->under_attack ) {
  361.                         if ( pplanet->mb != 0 )
  362.                                 printf("%2dmb", pplanet->mb);
  363.                         else
  364.                                 printf("    ");
  365.                         if ( pplanet->amb != 0 )
  366.                                 printf("%2damb", pplanet->amb);
  367.                 };
  368.         };
  369.         point(x_cursor,y_cursor + 1);
  370.  
  371.                                                 zero_tf(player,tfnum);
  372.                                                 pr3nt_tf(tfnum);
  373.                                         };
  374.                                 };
  375.                         };
  376.                 };
  377.         };
  378. }
  379.  
  380. quit()
  381. {
  382.         char answer;
  383.         cle2r_screen();
  384.         printf("Quit game....[verify]\n");
  385.         get_char(&answer);
  386.         if ( answer != 'Y' )
  387.                 printmap();
  388.         else {
  389.                 game_over = true;
  390.         };
  391. }
  392.  
  393. send_tf()
  394. {
  395.         char tf_move;
  396.         int tf_num;
  397.         boolean error;
  398.         printf("estination tf:");
  399.         get_char(&tf_move);
  400.         cle3r_left();
  401.         point(1,19);
  402.         tf_num = tf_move-'A'+1;
  403.         if ( (tf_num<1) || (tf_num>26) ) { 
  404.                 error_message();
  405.                 printf(" !illegal tf");
  406.         } 
  407.         else if ( tf[player][tf_num].dest==0 ) { 
  408.                 error_message();
  409.                 printf(" !nonexistent tf");
  410.         } 
  411.         else if ( (tf[player][tf_num].eta != 0) &&
  412.             ( (tf[player][tf_num].eta != tf[player][tf_num].origeta) ||
  413.             (tf[player][tf_num].withdrew) )
  414.             ) { 
  415.                 error_message();
  416.                 printf(" !Tf is not in normal space  ");
  417.         } 
  418.         else if ( tf[player][tf_num].blasting ) { 
  419.                 error_message();
  420.                 printf(" !Tf is blasting a planet");
  421.         } 
  422.         else {
  423.                 tf[player][tf_num].withdrew = false;
  424.                 set_des(tf_num,&error);
  425.         };
  426. }
  427.  
  428.